/**
 * 
 */
package demo.tellurium.test.cqp;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import demo.tellurium.framework.BaseTelluriumJUnitTestCase;
import demo.tellurium.module.cqp.CQPAllDocumentsModule;
import demo.tellurium.module.cqp.CQPAnswerModule;
import demo.tellurium.module.cqp.CQPLoginModule;
import demo.tellurium.module.cqp.CQPProfileModule;

/**
 * @author roger.xu
 * 
 */
public class AnswerQuestionJUnitTestCase extends BaseTelluriumJUnitTestCase {

    private static CQPLoginModule cqpLogin;
    private static CQPAllDocumentsModule cqpAllDocuments;
    private static CQPProfileModule cqpProfile;
    private static CQPAnswerModule cqpAnswer;

    @BeforeClass
    public static void initUi() {
        cqpLogin = new CQPLoginModule();
        cqpLogin.defineUi();

        cqpAllDocuments = new CQPAllDocumentsModule();
        cqpAllDocuments.defineUi();

        cqpProfile = new CQPProfileModule();
        cqpProfile.defineUi();

        cqpAnswer = new CQPAnswerModule();
        cqpAnswer.defineUi();
    }

    @Before
    public void delay() {
        waitingDelay();
    }

    @Test
    public void connectTo() {
        String contextUrl = getProperty("cqp.context.url");
        String pagePath = getProperty(CQPAllDocumentsModule.PATH_KEY);
        String url = String.format("%s/%s", contextUrl, pagePath);
        connectUrl(url);
    }

    @Ignore
    @Test
    public void connectToAnswerPage() {
        String contextUrl = getProperty("cqp.context.url");
        String pagePath = getProperty(CQPAnswerModule.PATH_KEY);
        String url = String.format("%s/%s?wpid=%d", contextUrl, pagePath, 260);
        connectUrl(url);
    }

    @Test
    public void testLogin() {
        console.debug("[testLogin]");
        // cqpLogin.doAdminLogin();
        String username = getProperty("cqp.login.username");
        String password = getProperty("cqp.login.password");
        cqpLogin.doLogin(username, password);
        pauseSec(3);
    }

    @Test
    public void testOpenProfilePage() {
        console.debug("[testOpenProfilePage]");
        cqpAllDocuments.doClickDocument(2);
    }

    @Test
    public void testOpenAnswerPage() {
        console.debug("[testOpenAnswerPage]");
        cqpProfile.doClickNextButton();
    }

    @Test
    public void testAnswerQuestion() {
        console.debug("[testAnswerQuestion]");
        pauseSec(3);
        cqpAnswer.doAnswerQuestion();
        manualBreak();
    }
}
